package com.panda.delivery.dialog;

import com.facebook.react.bridge.Promise;
import com.panda.delivery.R;
import com.panda.delivery.model.DialogBean;

import android.app.Activity;
import android.text.Html;
import android.view.View;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.TextView;

import razerdp.basepopup.BasePopupWindow;

/**
 * 单个按钮对话框
 */
public class OkDialog extends BasePopupWindow implements View.OnClickListener
{
    private TextView mTvTitle;
    private TextView mDialogMessage;
    private Button mDialogBtnOk;
    DialogBean mDialogBean;
    Promise mPromise;
    public OkDialog(Activity context,DialogBean bean, Promise promise)
    {
        super(context);
        mDialogBean=bean;
        mPromise = promise;
        setPopupWindowFullScreen(true);
        assignViews();
    }

    private void assignViews() {
        mTvTitle = findViewById(R.id.tv_title);
        mDialogMessage = findViewById(R.id.dialog_message);
        mDialogBtnOk = findViewById(R.id.dialog_btn_ok);
        setViewClickListener(this, mDialogBtnOk);
        mTvTitle.setText(mDialogBean.getTitle());
        mDialogMessage.setText(Html.fromHtml(mDialogBean.getContent()));
        mDialogBtnOk.setText(mDialogBean.getOkStr());
    }

    @Override
    protected Animation onCreateShowAnimation() {
        return null;
    }

    @Override
    protected Animation onCreateDismissAnimation() {
        return null;
    }

    @Override
    public View onCreateContentView()
    {
        return createPopupById(R.layout.dialog_ok);
    }

    @Override
    public void onClick(View v)
    {
        dismiss();
        mPromise.resolve("");
    }
}
